package com.example.team.controller;

import com.example.team.entity.Department;
import com.example.team.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：代志雄
 * 2023年11月3日11点23分
 */
@RestController
@Api(tags = "部门管理")
public class Departmentontroller {
    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "添加部门",
            notes = "成功返回1")
    @RequestMapping(value="/insertDepartment",method = {RequestMethod.GET})
    public int insertDepartment(Department department){
        return departmentService.insertDepartment(department);
    }

    @ApiOperation(value = "删除部门",
            notes = "成功返回1")
    @RequestMapping(value="/deleteDepartment",method = {RequestMethod.GET})
    public int deleteDepartment(int id){
        Department department=new Department();
        department.setDepartmentId(id);
        return departmentService.deleteDepartment(department);
    }

    @ApiOperation(value = "修改部门信息",
            notes = "成功返回1")
    @RequestMapping(value="/updateDepartment",method = {RequestMethod.GET})
    public int updateDepartment(Department department){
        return departmentService.updateDepartment(department);
    }

    @ApiOperation(value = "查询所有部门信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getAllDepartment",method = {RequestMethod.GET})
    public List<Department> getAllDepartment(String name){
        Department department=new Department();
        department.setDepartmentName(name);
        return departmentService.getAllDepartment(department);
    }

    @ApiOperation(value = "查询部门信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getDepartment",method = {RequestMethod.GET})
    public Department getDepartment(String name){
        Department department=new Department();
        department.setDepartmentName(name);
        return departmentService.getDepartment(department);
    }
}